﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/User.Master" AutoEventWireup="true" CodeBehind="LoanList.aspx.cs" Inherits="CRMWeb.Pages.AM.LoanList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        var ascSort = true;
        $(document).ready(function () {
            $('#dgLoanList').datagrid({
                title: ' Loan Information ' + setPanelText(),
                onDblClickRow: function (index, rowdata) {
                    window.location.href = "/Pages/AM/LoanSelectionMenu.aspx?LoanID=" + rowdata.LoanID;
                },
                onSortColumn: function (sort, order) {

                    if (ascSort == true) {
                        var Sorting = sort + ' ' + 'Asc';
                        quickSearch(Sorting);
                        ascSort = false;
                    }
                    else {
                        var Sorting = sort + ' ' + 'Desc';
                        quickSearch(Sorting);
                        ascSort = true;
                    }
                },
                onLoadSuccess: function (data) {
                    if (data.rows.length == 1)
                        window.location.href = "/Pages/AM/LoanSelectionMenu.aspx?LoanID=" + data.rows[0].LoanID;
                }
            });
        });
        function setPanelText() {
            var str;
            var cookieText = getCookie('LastSearchLoan');

            if ((cookieText == '') && ($('#txtSearchValue').val() == ''))
                str = '';

            else if ($('#txtSearchValue').val() != '' && cookieText == '')
                str = '( ' + $('#cmbSearchField').combobox('getText') + ' ' + $('#cmbSearchOperator').combobox('getText') + ' ' + $('#txtSearchValue').val() + ')';
            else if ($('#txtSearchValue').val() == '' && cookieText != '')
                str = '(SurName=' + cookieText + ')';
            else if ((cookieText != '') && ($('#txtSearchValue').val() != ''))
                str = '(SurName=' + cookieText + ', ' + $('#cmbSearchField').combobox('getText') + ' ' + $('#cmbSearchOperator').combobox('getText') + ' ' + $('#txtSearchValue').val() + ')';

            return str;
        }
        function quickSearch(sortText) {
            var cmbSearchField = $('#cmbSearchField').combobox('getValue');
            var cmbSearchOperator = $('#cmbSearchOperator').combobox('getValue');
            var txtSearchValue = $('#txtSearchValue').val();
            var strcondition = ' and ';
            if (cmbSearchField == 'LoanID') {
                if (cmbSearchOperator == '=')
                    strcondition += cmbSearchField + cmbSearchOperator + txtSearchValue;
            }
            else {
                if (cmbSearchOperator == ' like ' || cmbSearchOperator == '  like  ') {
                    if (cmbSearchOperator == '  like  ')
                        strcondition += cmbSearchField + cmbSearchOperator + '\'' + txtSearchValue + '%\'';
                    else
                        strcondition += cmbSearchField + cmbSearchOperator + '\'%' + txtSearchValue + '%\'';
                }
                else
                    strcondition += cmbSearchField + cmbSearchOperator + '\'' + txtSearchValue + '\'';
            }
            $('#dgLoanList').datagrid({
                title: ' Loan Information ' + setPanelText(),
                url: '/WebServices/AM/LoanForm.ashx?method=GetAllLoans&searchtext=' + getCookie('LastSearchLoan') + '&conditiontext=' + strcondition + '&sortCondition=' + sortText
            });
        }

        function formatDate(value, row) {
            if (value == null)
                return '';
            var date = new Date(value);
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return (d < 10 ? ('0' + d) : d) + '/' + (m < 10 ? ('0' + m) : m) + '/' + y;
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="dgLoanList" title="Loan Information" class="easyui-datagrid"
        pagination="true" autorowheight="true" data-options="url: '/WebServices/AM/LoanForm.ashx?method=GetAllLoans&searchtext=' + getCookie('LastSearchLoan'),pageSize:30,toolbar:'#tbLoanList'"
        rownumbers="true" fitcolumns="true" singleselect="true" align="center">
        <thead>
            <tr>
                <th field="LoanID" width="40" sortable="true">LoanID</th>
                <th field="Lender" width="40" sortable="true">Lender</th>
                <th field="Product" width="50" sortable="true">Contract</th>
                <th field="Purpose" width="40" sortable="true">Facility</th>
                <th field="LoanTerm" width="40" sortable="true">Loan Term</th>
                <th field="CreateDate" width="40" sortable="true" data-options="formatter:formatDate">CreateDate</th>
                <th field="EditDate" width="40" sortable="true" data-options="formatter:formatDate">EditDate</th>
            </tr>
        </thead>
    </table>
    <div id="tbLoanList" style="padding: 5px; height: auto">
        Field: 
            <select id="cmbSearchField" class="easyui-combobox" panelheight="auto" style="width: 100px">
                <option value="Lender">Lender</option>
                <option value="LoanID">LoanID</option>
                <option value="Product">Contract</option>
                <option value="Purpose">Facility</option>
                <option value="LoanTerm">LoanTerm</option>
                <option value="DrawDownDate">DrawDownDate</option>
                <option value="FirstPaymentDue">FirstPaymentDue</option>
            </select>
        Operator: 
            <select id="cmbSearchOperator" class="easyui-combobox" panelheight="auto" style="width: 100px">
                <option value="  like  ">Start With</option>
                <option value=" like ">Contains</option>
                <option value="=">Equals</option>
            </select>
        Value:
        <input id="txtSearchValue" class="easyui-validatebox" />
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-search" onclick="quickSearch(' ')"></a>
    </div>

   <script type="text/javascript">
       fnLeftNavSelected('menu_loan');
        
       function formatDate(value, row) {
           if (value == null)
               return '';
           var date = new Date(value);
           var y = date.getFullYear();
           var m = date.getMonth() + 1;
           var month = '';
           switch (m) {
               case 1:
                   month = 'Jan';
                   break;
               case 2:
                   month = 'Feb';
                   break;
               case 3:
                   month = 'Mar';
                   break;
               case 4:
                   month = 'Apr';
                   break;
               case 5:
                   month = 'May';
                   break;
               case 6:
                   month = 'Jun';
               case 7:
                   month = 'Jul';
                   break;
               case 8:
                   month = 'Aug';
                   break;
               case 9:
                   month = 'Sep';
                   break;
               case 10:
                   month = 'Oct';
                   break;
               case 11:
                   month = 'Nov';
                   break;
               case 12:
                   month = 'Dec';
                   break;
           }
           var d = date.getDate();
           return (d < 10 ? ('0' + d) : d) + ' ' + month + ' ' + y;
       }
   </script>
</asp:Content>
